//
//  GuideZengZhiView.m
//  YunDongGym
//
//  Created by lqq on 2018/8/23.
//  Copyright © 2018年 lqq. All rights reserved.
//

#import "GuideZengZhiView.h"
#import "NSDate+Extension.h"
@interface GuideZengZhiView ()<UIGestureRecognizerDelegate>
@property (weak, nonatomic) IBOutlet UIView *contentBackView;
@property (weak, nonatomic) IBOutlet UIButton *openBtn;

@end

@implementation GuideZengZhiView
+ (void)showGuideZengZhiView
{
    GuideZengZhiView *guideView =[[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([GuideZengZhiView class]) owner:nil options:nil] lastObject];
    [guideView show];
}
-(void)awakeFromNib
{
    [super awakeFromNib];
    _contentBackView.layer.cornerRadius = 2;
    _contentBackView.layer.masksToBounds = YES;
    _openBtn.layer.cornerRadius = 2;
    _openBtn.layer.masksToBounds= YES;
}
- (void)show
{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    self.frame = window.bounds;
    [window addSubview:self];
    self.backgroundColor = [UIColor clearColor];
    [UIView animateWithDuration:0.3 animations:^{
        self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
    }];
    
    UITapGestureRecognizer *tapGes = [[UITapGestureRecognizer alloc] init];
    [tapGes addTarget:self action:@selector(handleGesture:)];
    tapGes.delegate = self;
    [self addGestureRecognizer:tapGes];
}

- (IBAction)openBtnClicked:(id)sender {
    
    [self removeFromSuperview];
    [YDAlertViewController alertViewControllerWithMessage:@"请前往公众号【云动助手】进行开通高级版服务" cancleTitle:@"取消" confimTitle:@"复制公众号名称" cancleBlock:nil confimBlock:^{
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        pasteboard.string = @"云动助手";
        [AV showSuccess:@"公众号【云动助手】已添加到剪切板"];
    }];
}

- (void)handleGesture:(UITapGestureRecognizer *)tap
{
    CGPoint point = [tap locationInView:self];
    if (!CGRectContainsPoint(self.contentBackView.frame, point)) {
        [self removeFromSuperview];
    }
}

@end
